import EventConfig from "../data/EventConfig";
import Kits from "../kit/Kits";
import UIManager from "../manager/UIManager";
import ChooseEventWindow from "./ChooseEventWindow";
import EventName from "./EventName";
import OperateData from "./OperateData";
import UserData from "./UserData";


const { ccclass, property } = cc._decorator;

@ccclass
export default class GameUI extends cc.Component {

    @property(cc.Sprite)
    dogIcon: cc.Sprite = null;

    @property(cc.Node)
    nodeTopInfo: cc.Node = null;

    @property(cc.Label)
    lbName: cc.Label = null;

    @property(cc.Label)
    lbHost: cc.Label = null;

    @property(cc.Label)
    lbValue: cc.Label = null;

    @property(cc.Label)
    lbOther: cc.Label = null;

    start() {

        cc.director.getScene().on(EventName.UPDATE_GAME_CONTENT, this.updateUI, this);
        this.updateUI();
    }

    updateUI() {
        if (UserData.getInstance().birthData) {
            this.nodeTopInfo.active = true;

            this.lbName.string = `名字: ${UserData.getInstance().birthData.name}`;
            this.lbHost.string = "Jack的宠物";
            this.lbValue.string = `0`;//UserData.getInstance().birthData.value;
            this.lbOther.string = "";

            let path = `picture/dog/dog${UserData.getInstance().birthData.species}`;
            Kits.loadSpriteFrame(this.dogIcon, path)

        } else {
            this.nodeTopInfo.active = false;
        }
    }


    private addAge() {
        OperateData.addAge();
        UIManager.openWindow(ChooseEventWindow);
    }

    private openBirthPanel() {
        OperateData.beginBirth(null);
        cc.director.getScene().emit(EventName.UPDATE_GAME_CONTENT)

    }

    private onClickAddAge() {
        if (UserData.getInstance().birthData) {
            this.addAge();
        } else {
            this.openBirthPanel();
        }
    }

}
